#ifndef __USART_H
#define __USART_H

#include "stm32f10x.h"                  // Device header
#include <stdarg.h>
#include "stdio.h"
#include "sys.h"

#define SERIAL  USART1
#define SCANNER USART2
#define RS485   USART3

#define DMA_Channel_Serial  DMA1_Channel5
#define DMA_Channel_Scanner DMA1_Channel6
#define DMA_Channel_RS485   DMA1_Channel3

#define BUFF_SIZE   (128-2)

typedef struct
{
    uint8_t complete;
    uint8_t length;
    uint8_t payload[BUFF_SIZE];
} uart_dataBuffer_t;

typedef struct 
{
    uart_dataBuffer_t serial;
    uart_dataBuffer_t scanner;
    uart_dataBuffer_t rs485;
} uart_message_t;

extern uart_message_t uart_msg;

void UART1_Serial_Init(uint32_t baud_rate);
void UART2_Scanner_Init(uint32_t baud_rate);
void UART3_RS485_Init(uint32_t baud_rate);

void UART_SendArray(USART_TypeDef* Port, uint8_t *Array, uint16_t Length);
void UART_Printf(USART_TypeDef* Port, char *format, ...);

uint8_t Serial_Get(void);
uint8_t Scanner_Get(void);
uint8_t RS485_Get(void);

#endif
